package cn.org.tpeach.nosql.view;


import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.skin.TextFieldSkin;

public class PasswordShowTextFiledSkin extends TextFieldSkin {

    public PasswordShowTextFiledSkin(TextField textField) {
        super(textField);
    }
    static final char BULLET = '●';
    @Override
    protected String maskText(String txt) {
        if (getSkinnable() instanceof PasswordField) {
            char bullet = BULLET;
            if(getSkinnable() instanceof  PasswordShowField){
                PasswordShowField passwordShowField = (PasswordShowField) getSkinnable();
                if(passwordShowField.isShowPassword()){
                    return txt;
                }
                bullet = passwordShowField.getBullet();
            }
            int n = txt.length();
            StringBuilder passwordBuilder = new StringBuilder(n);
            for (int i = 0; i < n; i++) {
                passwordBuilder.append(bullet);
            }

            return passwordBuilder.toString();
        } else {
            return txt;
        }

    }
}
